package cn.kevinproject.dingtalk_robot.msg;

import com.dingtalk.api.request.OapiRobotSendRequest;
import lombok.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author kevin lau
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
public class MultiActionCardMessage extends ActionCardMessage {

    private List<Button> btns;


    public MultiActionCardMessage() {

        this.msgType = "actionCard";
    }

    @Override
    public OapiRobotSendRequest buildRequest() {
        val request = super.buildRequest();
        val actionCard = new OapiRobotSendRequest.Actioncard();
        actionCard.setText(getText());
        actionCard.setTitle(getTitle());
        actionCard.setBtnOrientation(getBtnOrientation());
        actionCard.setBtns(btns.stream().map(t -> {
            val btn = new OapiRobotSendRequest.Btns();
            btn.setTitle(t.getTitle());
            btn.setActionURL(t.getActionUrl());
            return btn;
        }).collect(Collectors.toList()));
        request.setActionCard(actionCard);
        return request;
    }

    @Data
    public static class Button {

        private String title;

        private String actionUrl;
    }
}
